#include <iostream>
using namespace std;

const int N = 100010;
int a[N], b[N];
int n;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
        scanf("%d", a + i);
    int ans = 0;
    for (int i = 0, j = 0; i < n; ++i)
    {
        b[a[i]]++;
        while (i > j && b[a[j]] > 1)
            b[a[j++]]--;
        ans = max(ans, i + 1 - j);
    }
    printf("%d", ans);
    return 0;
}